package com.xiaoshuidi.cloud.module.bpm.enums.swo;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.xiaoshuidi.cloud.framework.common.exception.ErrorCode;
import com.xiaoshuidi.cloud.framework.common.exception.ServiceException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 服务工单 - 服务类型枚举
 */
@Getter
@AllArgsConstructor
public enum SwoServiceTypeEnum {

    MAINTENANCE("维修", 1),
    CLEANING("保洁", 2),
    OTHER("其他", 3),
    COMPLAINTS("投诉", 4),
    MOVE("搬家", 5),
    SHARED_SPACE("共享空间", 6),
    FURNITURE_LEASING("家具租赁", 7),
    ;

    private String name;
    private Integer value;

    public static String getNameByValue(Integer value) {
        SwoServiceTypeEnum swoServiceTypeEnum = Arrays.stream(SwoServiceTypeEnum.values()).filter(p -> p.getValue().equals(value)).findFirst().orElse(null);
        if(ObjectUtil.isEmpty(swoServiceTypeEnum)){
            throw new ServiceException(new ErrorCode(100322, StrUtil.format("服务工单服务类型枚举value{}不存在",value)));
        }
        return swoServiceTypeEnum.getName();    }
}
